package control.util.astar
{
	/**
	 * 寻路用的节点信息
	 * @author 
	 * 
	 */	
	public class NodeGrid 
	{
		private var _nodes : Array;
		private var nodes_2x : Array;
		private var _numCols : int;
		private var _numRows : int;
		public function NodeGrid(numCols : int,numRows : int) 
		{
			_nodes = new Array();
			nodes_2x = new Array();
			upDateCrid(numCols, numRows);
		}
		
		private function upDateCrid(numCols : int,numRows : int) : void 
		{
			_numCols = numCols;
			_numRows = numRows;
			var col : int = 0;
			var row : int = 0;
			var n : int = 0;
			var id : int = 0;
			for (var i : int = 0;i < _numCols;i++) 
			{
				_nodes[i] = new Array();
				col = n;
				row = _numCols - col;
				n += 1;
				id = 0;
				for (var j : int = 0;j < _numRows;j++) 
				{
					_nodes[i][j] = new Node(col, row);
					(_nodes[i][j] as Node).tx = i;
					(_nodes[i][j] as Node).ty = j;
					if (id == 0) 
					{
						col += 1;
						id = 1;
					} else 
					{
						row += 1;
						id = 0;
					}
				}
			}
			kelisArr(_numCols + _numRows);
		}
		private function kelisArr(kelis_num : int) : void 
		{
			for (var i : int = 0;i <= kelis_num;i++) 
			{
				nodes_2x[i] = new Array  ;
				for (var j : int = 0;j <= kelis_num;j++) 
				{
					nodes_2x[i][j] = new Node(0, 0);
				}
			}
			for (i = 0;i < _nodes.length;i++) 
			{
				for (j = 0;j < (_nodes[i] as Array).length;j++) 
				{
					nodes_2x[(_nodes[i][j] as Node).x][(_nodes[i][j] as Node).y] = _nodes[i][j];
				}
			}
		}
		public function getNode(col : int,row : int) : Node 
		{
			return _nodes[col][row] as Node;
		}
		public function getNodes() : Array 
		{
			return _nodes;
		}
		public function get2XNode(col : int,row : int) : Node 
		{
			return nodes_2x[col][row] as Node;
		}
		public function get2XNodes() : Array 
		{
			return nodes_2x as Array;
		}
		public function get numCols() : int 
		{
			return _numCols;
		}
		public function get numRows() : int 
		{
			return _numRows;
		}
	}
}